package com.solcoo.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Repository;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.solcoo.pojo.Menu;
import com.solcoo.pojo.MenuType;

@Repository
public class MenuDao {
	
	@Resource
	private SqlMapClient sqlMapClient;
	
	public boolean addMenu(Menu menu) throws SQLException {
		sqlMapClient.insert("addMenu", menu);
				
		if (menu.getId() != null)
			return true;
		else
			return false;
	}
	
	public boolean deleteMenuById(Long id) throws SQLException {
		return sqlMapClient.delete("deleteMenu", id) > 0 ? true : false;
	}
	
	public boolean updateMenu(Menu menu) throws SQLException {
		return sqlMapClient.update("updateMenu", menu) > 0 ? true : false;
	}
	
	public Menu getMenu(Long id) throws SQLException {
		return (Menu) sqlMapClient.queryForObject("getMenu", id);
	}
	
	public List<Menu> getMenuListByShanghuid(Map<String, Object> map) throws SQLException {
		return sqlMapClient.queryForList("getMenuListByShanghuid", map);
	}

	public void updateMenuByMenuType(MenuType menuType) throws SQLException {
		sqlMapClient.update("updateMenuByMenuType", menuType);
	}
}